package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.helper.widget.Carousel;
import androidx.constraintlayout.helper.widget.Carousel.Adapter;
import androidx.constraintlayout.motion.widget.MotionLayout;

public class MainActivity26 extends AppCompatActivity {

    private MotionLayout mRoot;
    private ImageView mImage00;
    private ImageView mImage01;
    private ImageView mImage02;
    private ImageView mImage03;
    private ImageView mImage04;
    private Carousel mCarousel;

    private int[] images = {
        R.drawable.bryce_canyon,
        R.drawable.cathedral_rock,
        R.drawable.death_valley,
        R.drawable.fitzgerald_marine_reserve,
        R.drawable.goldengate,
        R.drawable.golden_gate_bridge,
        R.drawable.shipwreck_1,
        R.drawable.shipwreck_2,
        R.drawable.grand_canyon,
        R.drawable.horseshoe_bend,
        R.drawable.muir_beach,
        R.drawable.rainbow_falls,
    };

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity26.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main26 );
        initView();
        initViewAction();
    }

    private void initView() {

        mRoot = (MotionLayout) findViewById( R.id.root );
        mImage00 = (ImageView) findViewById( R.id.image00 );
        mImage01 = (ImageView) findViewById( R.id.image01 );
        mImage02 = (ImageView) findViewById( R.id.image02 );
        mImage03 = (ImageView) findViewById( R.id.image03 );
        mImage04 = (ImageView) findViewById( R.id.image04 );
        mCarousel = (Carousel) findViewById( R.id.carousel );
    }

    private void initViewAction() {

        mCarousel.setAdapter( new Adapter() {
            @Override
            public int count() {

                return images.length;
            }

            @Override
            public void populate( View view, int index ) {

                if ( view instanceof ImageView ) {

                    ((ImageView) view).setImageResource( images[index] );
                }
            }

            @Override
            public void onNewItem( int index ) {

            }
        } );
    }
}